{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import bqplot.pyplot as plt\n",
    "from bqplot import LinearScale, Axis, Figure, Scatter"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "np.random.seed(0)\n",
    "size = 100\n",
    "x = range(size)\n",
    "y1 = np.cumsum(np.random.randn(size) * 100.0)\n",
    "y2 = np.cumsum(np.random.randn(size))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Miscellaneous Properties"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "fig = plt.figure()\n",
    "line = plt.plot(np.arange(10), np.arange(10), colors=['hotpink', 'orange'])\n",
    "fig"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# set the grid lines of axes to dashed\n",
    "xax, yax = plt.axes()['x'], plt.axes()['y']\n",
    "\n",
    "xax.grid_lines = 'dashed'\n",
    "yax.grid_lines = 'dashed'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Change the side of the axis\n",
    "yax.side = 'right'\n",
    "xax.side = 'top'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# change the orientation of axes\n",
    "yax.orientation = 'horizontal'\n",
    "xax.orientation = 'vertical'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Change the format of the ticks on the axis\n",
    "yax.tick_format = '0.2f'\n",
    "xax.tick_format = '0.0f'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Change the color of the axis\n",
    "with xax.hold_sync():\n",
    "    xax.color = 'orangered'\n",
    "    xax.label_color = 'orangered'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# change the grid colors\n",
    "xax.grid_color = 'red'"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Label Placement"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "fig = plt.figure()\n",
    "axes_options = {'x': {'label': 'X'}, 'y': {'label': 'Y'}}\n",
    "line = plt.plot(x, y1, colors=['orangered'], axes_options=axes_options)\n",
    "fig"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "xax, yax = plt.axes()['x'], plt.axes()['y']\n",
    "\n",
    "# moving the label along the axis\n",
    "xax.label_location = 'end'\n",
    "yax.label_location = 'start'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# moving the label perpendicular to the axis\n",
    "yax.label_offset = '6ex'\n",
    "xax.label_offset = '-1em'"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ticks properties"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "scrolled": false
   },
   "outputs": [],
   "source": [
    "fig = plt.figure()\n",
    "line = plt.plot(x[:20], y1[:20], 'm')\n",
    "fig"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "xax, yax = plt.axes()['x'], plt.axes()['y']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Setting the number of ticks\n",
    "xax.num_ticks = 8"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Setting the tick values\n",
    "xax.tick_values = np.arange(1, 21)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Setting the style for the text of the ticks\n",
    "xax.tick_style = {'stroke': 'orangered', 'font-size': 14}"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Axis Placement"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# using object model for this example\n",
    "sc_x = LinearScale()\n",
    "sc_y = LinearScale(reverse=True)\n",
    "sc_y2 = LinearScale()\n",
    "\n",
    "sc1 = Scatter(x=x[:10], y=y1[:10], \n",
    "              scales={'x': sc_x, 'y': sc_y},\n",
    "              default_size=100)\n",
    "\n",
    "sc2 = Scatter(x=x[:10], y=y2[:10],\n",
    "              colors=['dodgerblue'],\n",
    "              marker='cross', scales={'x': sc_x, 'y': sc_y2})"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Placement of axis in terms of figure scales"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "## Setting offset for axis in terms of figure scales\n",
    "xax = Axis(label='Test X', scale=sc_x, \n",
    "            grid_lines='solid', offset=dict(value=0.2), label_location=\"start\")\n",
    "\n",
    "yax = Axis(label='Test Y', scale=sc_y, \n",
    "           orientation='vertical', tick_format='0.2f', \n",
    "           grid_lines='solid', label_location=\"end\")\n",
    "\n",
    "yax2 = Axis(label='Test Y2', scale=sc_y2, orientation='vertical', side='right', \n",
    "            tick_format='0.2f')\n",
    "Figure(axes=[xax, yax, yax2], marks=[sc1, sc2], legend_location='top-right',\n",
    "       padding_x=0.025)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# restoring to default position\n",
    "xax.offset = {}"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Placement of axis in terms of actual scales and data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "yax.offset = dict(value=3.0, scale=sc_x)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Color Axis"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# add a fig margin to allow place for color bar\n",
    "fig = plt.figure(fig_margin=dict(top=80, left=80, right=80, bottom=80))\n",
    "scatter = plt.scatter(x, y1, color=y2, stroke='black')\n",
    "fig"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Changing side and orientation of color axis"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "xax, yax, cax = plt.axes()['x'], plt.axes()['y'], plt.axes()['color']\n",
    "cax.side = 'top'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "with cax.hold_sync():\n",
    "    cax.orientation = 'vertical'\n",
    "    cax.side = 'right'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "yax.side = 'right'\n",
    "cax.side = 'left'"
   ]
  }
 ],
 "metadata": {
  "anaconda-cloud": {},
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
